home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / spacei_1 / frmscore.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-01-27  |  9.7 KB  |  301 lines

  1. VERSION 5.00
  2. Begin VB.Form FrmScores 
  3.    BackColor       =   &H0000FF00&
  4.    Caption         =   "-----Scores--------"
  5.    ClientHeight    =   4605
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   4320
  9.    Icon            =   "FrmScores.frx":0000
  10.    KeyPreview      =   -1  'True
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   307
  15.    ScaleMode       =   3  'Pixel
  16.    ScaleWidth      =   288
  17.    StartUpPosition =   1  'CenterOwner
  18.    Begin VB.TextBox TxtPlayerNameChange 
  19.       Alignment       =   2  'Center
  20.       Appearance      =   0  'Flat
  21.       BackColor       =   &H80000009&
  22.       BorderStyle     =   0  'None
  23.       Enabled         =   0   'False
  24.       Height          =   615
  25.       Left            =   1320
  26.       MaxLength       =   15
  27.       TabIndex        =   5
  28.       TabStop         =   0   'False
  29.       Top             =   2400
  30.       Width           =   1935
  31.    End
  32.    Begin VB.CommandButton CmdChangeName 
  33.       Caption         =   "&Change PlayerName"
  34.       Height          =   615
  35.       Left            =   0
  36.       TabIndex        =   3
  37.       Tag             =   "SV"
  38.       Top             =   720
  39.       Width           =   1095
  40.    End
  41.    Begin VB.CommandButton CmdRndNumber 
  42.       Caption         =   "&Random Number"
  43.       Height          =   615
  44.       Left            =   0
  45.       TabIndex        =   4
  46.       Tag             =   "SV"
  47.       Top             =   0
  48.       Width           =   1095
  49.    End
  50.    Begin VB.CommandButton CmdDisplayWinner 
  51.       Caption         =   "&Display Winner"
  52.       Height          =   615
  53.       Left            =   0
  54.       TabIndex        =   2
  55.       Tag             =   "SV"
  56.       Top             =   1440
  57.       Width           =   1095
  58.    End
  59.    Begin VB.CommandButton CmdWriteFile 
  60.       Caption         =   "&Write File"
  61.       Height          =   615
  62.       Left            =   0
  63.       TabIndex        =   1
  64.       Tag             =   "SV"
  65.       Top             =   2160
  66.       Width           =   1095
  67.    End
  68.    Begin VB.CommandButton CmdReadFile 
  69.       Caption         =   "R&ead File"
  70.       Height          =   615
  71.       Left            =   0
  72.       TabIndex        =   0
  73.       Tag             =   "SV"
  74.       Top             =   2880
  75.       Width           =   1095
  76.    End
  77.    Begin VB.Label lblScore 
  78.       Alignment       =   2  'Center
  79.       Height          =   615
  80.       Index           =   0
  81.       Left            =   3480
  82.       TabIndex        =   15
  83.       Top             =   0
  84.       Width           =   615
  85.    End
  86.    Begin VB.Label lblScore 
  87.       Alignment       =   2  'Center
  88.       Height          =   615
  89.       Index           =   1
  90.       Left            =   3480
  91.       TabIndex        =   14
  92.       Top             =   600
  93.       Width           =   615
  94.    End
  95.    Begin VB.Label lblPlayer 
  96.       Alignment       =   2  'Center
  97.       Caption         =   "Player1"
  98.       Height          =   615
  99.       Index           =   0
  100.       Left            =   1320
  101.       TabIndex        =   13
  102.       Top             =   0
  103.       Width           =   1935
  104.    End
  105.    Begin VB.Label lblPlayer 
  106.       Alignment       =   2  'Center
  107.       Caption         =   "Player2"
  108.       Height          =   615
  109.       Index           =   1
  110.       Left            =   1320
  111.       TabIndex        =   12
  112.       Top             =   600
  113.       Width           =   1935
  114.    End
  115.    Begin VB.Label lblWinner 
  116.       Alignment       =   2  'Center
  117.       Height          =   615
  118.       Left            =   1200
  119.       TabIndex        =   11
  120.       Top             =   3720
  121.       Width           =   2175
  122.    End
  123.    Begin VB.Label lblScore 
  124.       Alignment       =   2  'Center
  125.       Height          =   615
  126.       Index           =   2
  127.       Left            =   3480
  128.       TabIndex        =   10
  129.       Top             =   1200
  130.       Width           =   615
  131.    End
  132.    Begin VB.Label lblScore 
  133.       Alignment       =   2  'Center
  134.       Height          =   615
  135.       Index           =   3
  136.       Left            =   3480
  137.       TabIndex        =   9
  138.       Top             =   1800
  139.       Width           =   615
  140.    End
  141.    Begin VB.Label lblPlayer 
  142.       Alignment       =   2  'Center
  143.       Caption         =   "Player3"
  144.       Height          =   615
  145.       Index           =   2
  146.       Left            =   1320
  147.       TabIndex        =   8
  148.       Top             =   1200
  149.       Width           =   1935
  150.    End
  151.    Begin VB.Label lblPlayer 
  152.       Alignment       =   2  'Center
  153.       Caption         =   "Player4"
  154.       Height          =   615
  155.       Index           =   3
  156.       Left            =   1320
  157.       TabIndex        =   7
  158.       Top             =   1800
  159.       Width           =   1935
  160.    End
  161.    Begin VB.Label lblPrompt 
  162.       Alignment       =   2  'Center
  163.       Height          =   615
  164.       Left            =   1320
  165.       TabIndex        =   6
  166.       Top             =   3000
  167.       Width           =   1935
  168.    End
  169. Attribute VB_Name = "FrmScores"
  170. Attribute VB_GlobalNameSpace = False
  171. Attribute VB_Creatable = False
  172. Attribute VB_PredeclaredId = True
  173. Attribute VB_Exposed = False
  174. '----------FrmScores -------------------------
  175. 'score information in convenient block
  176. Private Sub Form_Load()
  177.     Dim index As Integer 'to go through player array
  178.     'update labels
  179.     For index = 0 To 3 '4 labels
  180.         lblPlayer(index).Caption = players(index).name
  181.         lblScore(index).Caption = players(index).score
  182.     Next 'index
  183. End Sub 'form-load
  184. Private Sub TxtPlayerNameChange_KeyPress(KeyAscii As Integer)
  185. 'algorithm: if press return key and previously a number 1..4 was
  186. 'pressed then restore state of label focus of cmd button'change playername
  187. 'also turn labels and textinput off;
  188. 'else if we have a number 1..4 then calculate which player and
  189. 'redden his label and delete text input
  190. 'else if we've had a number-numberokay- then refresh label
  191. Dim index
  192. Static playertochange
  193. Static numberokay As Boolean
  194.     If KeyAscii = 13 And numberokay Then
  195.         lblPlayer(playertochange).BackColor = vbButtonFace
  196.         lblPlayer(playertochange).ForeColor = &H80000012
  197.         lblPlayer(playertochange).Caption = TxtPlayerNameChange.Text
  198.         players(playertochange).name = TxtPlayerNameChange.Text
  199.         '
  200.         lblPrompt.Caption = ""
  201.         numberokay = False
  202.         CmdChangeName.SetFocus
  203.         TxtPlayerNameChange.Text = ""
  204.         TxtPlayerNameChange.Enabled = False
  205.         
  206.     Else
  207.         If KeyAscii >= Asc("1") And KeyAscii <= Asc("4") And numberokay = False Then
  208.             playertochange = KeyAscii - Asc("0") - 1 '49("1")-52("4")ascii changed to 0..3
  209.             KeyAscii = 0 'throw away key
  210.             lblPlayer(playertochange).BackColor = &H2995522
  211.             lblPlayer(playertochange).ForeColor = &H2FFFFFF
  212.             TxtPlayerNameChange.Text = ""
  213.             lblPrompt.Caption = "Please Enter Player " & playertochange + 1
  214.             numberokay = True
  215.         Else
  216.             If numberokay Then
  217.                 'update label when input name
  218.                 lblPlayer(playertochange).Caption _
  219.                 = TxtPlayerNameChange.Text
  220.                 
  221.             Else
  222.             'throw key away and exit back to cmdchangeplayername
  223.             'with focus
  224.                 KeyAscii = 0
  225.                 TxtPlayerNameChange.Text = ""
  226.                 CmdChangeName.SetFocus
  227.                 TxtPlayerNameChange.Enabled = False
  228.             End If
  229.         End If
  230.     End If
  231. End Sub 'TxtPlayerNameChange-KeyPress
  232. Private Sub CmdReadFile_Click()
  233. Dim index, inname, inscore
  234.     index = 0
  235.     On Error GoTo out ' jump to out to avoid error of no disk or filer
  236.     Open "A:\temp\playerdata" For Input As #1
  237.     For index = 0 To 3
  238.         Input #1, players(index).name, players(index).score
  239.         lblPlayer(index).Caption = players(index).name
  240.        
  241.         lblScore(index).Caption = players(index).score
  242.      
  243.     Next
  244.     Close #1
  245. End Sub 'CmdReadFile
  246. Private Sub CmdWriteFile_Click()
  247. Dim index
  248.   On Error GoTo out ' jump to out to avoid error of no disk or filer
  249.     Open "A:\temp\playerdata" For Output As #1
  250.     For index = 0 To 3
  251.         Write #1, players(index).name
  252.         Write #1, players(index).score
  253.     Next
  254.     Close #1
  255. End Sub 'CmdWriteFile
  256. Private Sub CmdChangeName_Click()
  257.     'change players names
  258.     TxtPlayerNameChange.Enabled = True
  259.     'prompt on testbox
  260.     TxtPlayerNameChange.Text = "   Which Player? 1..4"
  261.     TxtPlayerNameChange.SetFocus
  262. End Sub 'CmdChangeName
  263. Private Sub CmdQuit_Click()
  264. End Sub
  265. Private Sub CmdRndNumber_Click()
  266. Dim index
  267. 'generate random number for each players score
  268. 'save in field players().score
  269.     For index = 0 To 3
  270.         players(index).score = Int(Rnd * 100 + 1)
  271.         'update lables
  272.         lblPlayer(index).Caption = players(index).name
  273.         lblScore(index).Caption = players(index).score
  274.         
  275.     Next
  276. End Sub 'CmdRndNumber-click
  277. Private Sub CmdDisplayWinner_Click()
  278.     'compare scores of players
  279.     Dim temp, x, winnerindex
  280.     temp = players(0).score
  281.     winnerindex = 0
  282.     For x = 0 To 3
  283.         If temp < players(x).score Then
  284.             temp = players(x).score
  285.             winnerindex = x
  286.         End If
  287.     Next
  288.     'output result
  289.     'what about 2 equal scores? not implemented yet
  290.     lblWinner.Caption = "Winner =  " & players(winnerindex).name + Chr$(13) & "Score= " & players(winnerindex).score
  291. End Sub 'CmdDisplayWinner-click
  292. Private Sub Form_Unload(Cancel As Integer)
  293.     'turn back on timers
  294.     With FrmGameScreen
  295.         .TmrClock.Enabled = True
  296.         .TmrEnergy1.Enabled = True
  297.         .TmrMoveAliens.Enabled = True
  298.         .TmrPlayerMissile.Enabled = True
  299.     End With
  300. End Sub 'form-unload
  301.